#ifndef __C_ANIMATED_BILLBOARD_SCENE_NODE_H_INCLUDED__
#define __C_ANIMATED_BILLBOARD_SCENE_NODE_H_INCLUDED__

#include <Irrlicht.h>
#include "ASprite.h"
#include "ASpriteInstance.h"

using namespace irr;
using namespace scene;

// own factory implementation
class CAnimatedBillboardSceneNodeFactory : public ISceneNodeFactory
{
public:

	CAnimatedBillboardSceneNodeFactory(ISceneManager* mgr);
	~CAnimatedBillboardSceneNodeFactory();

	virtual ISceneNode* addSceneNode(ESCENE_NODE_TYPE type, ISceneNode* parent=0);
	virtual ISceneNode* addSceneNode(const c8* typeName, ISceneNode* parent=0);
	virtual u32 getCreatableSceneNodeTypeCount() const;
	virtual const c8* getCreateableSceneNodeTypeName(u32 idx) const;
	virtual ESCENE_NODE_TYPE getCreateableSceneNodeType(u32 idx) const;
	virtual const c8* getCreateableSceneNodeTypeName(ESCENE_NODE_TYPE type) const;

private:

	ESCENE_NODE_TYPE getTypeFromName(const c8* name);
	ISceneManager* Manager;
};

//! Scene node which is a billboard using 2d sprite
//! which always looks to the camera. 
class CAnimatedBillboardSceneNode : virtual public ISceneNode
{
public:

	// id for my scene node
    static const int ANIMATED_BILLBOARD_SCENE_NODE_ID = MAKE_IRR_ID('a','b','i','l');

	//! constructor
	CAnimatedBillboardSceneNode(s32 id,	
		const core::vector3df& position);
	~CAnimatedBillboardSceneNode();

	//! pre render event
	virtual void OnRegisterSceneNode();

	//! render
	virtual void render();

	//! returns the axis aligned bounding box of this node
	virtual const core::aabbox3d<f32>& getBoundingBox() const;

	//! sets the size of the billboard
	virtual void setSize(const core::dimension2d<f32>& size);

	//! gets the size of the billboard
	virtual const core::dimension2d<f32>& getSize() const;

	//! Returns type of the scene node
	virtual ESCENE_NODE_TYPE getType() const { return (ESCENE_NODE_TYPE)ANIMATED_BILLBOARD_SCENE_NODE_ID; }

	//! Writes attributes of the scene node.
	virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0);

	//! Reads attributes of the scene node.
	virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);

	//! loads the sprite to render
	void LoadSprite(const char* spriteName);

	//! loads the texture to render
	void LoadTexture(const char* textureName);	

	ASprite* m_sprite;
	ASpriteInstance* m_spriteInstance;

private:

	core::dimension2d<f32> Size;
	core::aabbox3d<f32> BBox;
};


#endif

